package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* CollectView
* */
class CollectView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            style = Paint.Style.STROKE
            strokeWidth = mStrokeWidth
            color = context.resources.getColor(R.color.color_B96AF1)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            style = Paint.Style.STROKE
            strokeWidth = mStrokeWidth
            color = context.resources.getColor(R.color.color_E85F90)
        }
    }

    private val mPaint2 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            style = Paint.Style.STROKE
            strokeWidth = mStrokeWidth
            color = context.resources.getColor(R.color.color_384ECC)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2

            translate(cx, cy + cy * 3 / 10 / 2)

            mPath0.apply {
                reset()
                moveTo(cx * 9 / 10,-cy * 6 / 10)
                lineTo(0F, -cy * 9 / 10)
                lineTo(-cx * 9 / 10, -cy * 6 / 10)
                lineTo(0F, -cy * 3 / 10)
            }
            drawPath(mPath0, mPaint0)

            mPath0.apply {
                reset()
                moveTo(0F, -cy * 3 / 10)
                lineTo(cx * 9 / 10,-cy * 6 / 10)
                lineTo(cx * 9 / 10, cy * 3 / 10)
                lineTo(0F, cy * 6 / 10)
            }
            drawPath(mPath0, mPaint1)

            mPath0.apply {
                reset()
                moveTo(0F, -cy * 3 / 10)
                lineTo(0F,cy * 6 / 10)
                lineTo(-cx * 9 / 10, cy * 3 / 10)
                lineTo(-cx * 9 / 10, -cy * 6 / 10)
            }
            drawPath(mPath0, mPaint2)


//            mPath0.apply {
//                reset()
//                moveTo(cx * 4 / 7,-cy * 4 / 7)
//                lineTo(0F, -cy * 6 / 7)
//                lineTo(-cx * 4 / 7, -cy * 4 / 7)
//                lineTo(0F, -cy * 2 / 7)
//            }
//            drawPath(mPath0, mPaint0)

//            mPath0.apply {
//                reset()
//                moveTo(0F, -cy * 2 / 7)
//                lineTo(cx * 4 / 7,-cy * 4 / 7)
//                lineTo(cx * 4 / 7, cy * 1 / 7)
//                lineTo(0F, cy * 3 / 7)
//            }
//            drawPath(mPath0, mPaint1)
//
//            mPath0.apply {
//                reset()
//                moveTo(0F, -cy * 2 / 7)
//                lineTo(0F, cy * 3 / 7)
//                lineTo(-cx * 4 / 7, cy * 1 / 7)
//                lineTo(-cx * 4 / 7, -cy * 4 / 7)
//            }
//            drawPath(mPath0, mPaint2)
        }
    }
}